package com.yuan.java.thread.threadNotSafe;

public class Count1 {

    /**
     * 采用全局变量导致 num 数值一直往上加
     */
    private int num;

    public synchronized void count() {
        System.out.println("线程进入");
        for (int i = 1; i <= 10; i++) {
            num += i;
        }
        System.out.println(Thread.currentThread().getName() + "-" + num);
        System.out.println("线程结束");

    }


}